package ferp.android.dialogs;

import android.content.Context;

import java.util.ArrayList;

/**
 * User: olegs
 * Date: 15/07/2014 17:21
 */
public class ObjectRadioListViewDialog<T> extends RadioListViewDialog
{
  public interface Listener<T>
  {
    void onItemSelected(T selected);
  }

  public ObjectRadioListViewDialog(Context context, Listener<T> listener, int title)
  {
    super(context);

    this.listener = listener;
    this.title.setText(title);
  }

  @Override
  public void onItemClicked(int i)
  {
    listener.onItemSelected(values.get(i));

    dismiss();
  }

  protected void clear()
  {
    ld.options.clear();
    ld.enabled.clear();
    values.clear();
  }

  protected void add(int resource, T value, boolean enabled)
  {
    add(getContext().getString(resource), value, enabled);
  }

  protected void add(String option, T value, boolean enabled)
  {
    this.ld.options.add(option);
    this.ld.enabled.add(enabled);
    this.values.add(value);
  }

  private final ArrayList<T> values = new ArrayList<T>();
  private final Listener<T> listener;
}
